package demo;

public class Test {
    public static int removeDuplicates(int[] nums) {
        int index = 0;
        for(int i= 1;i<nums.length;i++){
            if(nums[i-1] !=nums[i]){
                nums[++index] = nums[i];

            }
        }
        return index+1;
    }
    //删除有序数组中的重复项
    public static void main(String[] args) {
        int[] nums = {0,0,1,1,1,2,2,3,3,4};
        System.out.println(removeDuplicates(nums));
/*      输出：
                5
                */

    }
    public static String truncateSentence(String s, int k) {
        for(int i = 0;i < s.length();i++){
            if(s.charAt(i) == ' ' && --k == 0){
                return s.substring(0,i);
            }
        }
        return s;
    }

    public static void main4(String[] args) {
        String s = "Hello how are you Contestant";
        int k = 4;
        System.out.println(truncateSentence(s, k));
    }
    public static void main3(String[] args) {
        int i = -5;
       // i = ++(i++);  //i++ 完了是 -4，不是变量了。那你++数字  那指定报错。
        System.out.println(i);
    }
    public static void main2(String[] args) {

            int x = 0;
            int y = 0;
            int k = 0;
            for (int z = 0; z < 5; z++) {
                if ((++x > 2) && (++y > 2) && (k++ > 2)){
                    x++;
                    ++y;
                    k++;
                }
            }
            System.out.println(x + "" +y + "" +k);

    }
    public static void main1(String[] args) {
        Double x = 1.2;
        long l = (long)1.2; //1.2 默认是double类型。
        float f = (float) (x/l); // x是Double，乘除完成还是Double类型。
        System.out.println(f);
    }
}
